<?php
class Model_Type {
    
    public function getAllType() {
        $sql = "Select * from type";
        $db = Model_Connections::getInstance()->getDbConnect();
        $data = $db->fetchAll($sql);
        return $data;
    }
    
    public function getTypeById($id) {
        $sql = "SELECT * FROM type where id = " . $id;
        $db = Model_Connections::getInstance()->getDbConnect();
        $data = $db->fetchAll($sql);
        return $data;
    }
    
     public function insertNewType($typeName) {
        if ($typeName == null || $typeName == "")
            return false;
        else {
            $db = Model_Connections::getInstance()->getDbConnect();
            return $db->query("Insert into type(name) values('$typeName')");
        }
    }

    public function deleteType($typeId) {
        if ($typeId == null || $typeId == "")
            return false;
        else {
            $db = Model_Connections::getInstance()->getDbConnect();
            return $db->query("DELETE FROM type WHERE id = '$typeId'");
        }
    }

    public function updateType($id, $name) {
        if ($id == null || $id == "" || $name == null || $name == "")
            return false;
        else {
            $db = Model_Connections::getInstance()->getDbConnect();
            return $db->query("UPDATE `type` SET `name`=N'".$name."' WHERE `id`='".$id."'");
        }
    }
    
}
?>
